package com.auto.api.core.type.json;

import com.auto.api.core.constants.MappingConstants;
import org.springframework.core.ResolvableType;

/**
 * @program:
 * @description: 类型转换接口
 * @author: liangshf
 * @create: 2020-09-24
 */
public abstract class AbstractTypeHandler<R> implements JsonTypeHandler {

    public abstract R getResultInstance();

    /**
     * 根据类型获取默认Json
     * @return
     */
    @Override
    public String getJson(ResolvableType resolvableType){
        if (resolvableType == null || MappingConstants.VOD.equals(resolvableType.getType().getTypeName())) {
            return MappingConstants.EMPTY_STRING;
        }
        R initResult = getResultInstance();
        return doResultJson(resolvableType, initResult);
    }

    public abstract String doResultJson(ResolvableType resolvableType, R initResult);

}
